<template>
	<view class="content">
		<!-- <view class="xslist" v-for="(item,index) in list1" >
			<view class="xs_title">假数据</view>
		</view> -->
		<view class="xslist" v-for="(item,index) in list" :key="index" @click="xsdetail(item.id,item.novel_id)">
			<view class="xs_title">{{item.name}}</view>
		</view>
		<uni-load-more :loadingType="loadingType" :contentText="contentText"  v-if="list.length != 0"></uni-load-more>
		
		<view class="wu" v-if="list.length == 0">暂无数据~</view>
	</view>
</template>

<script>
import getdata from '@/common/ajax.js';	
import uniLoadMore from '@/components/uni-load-more.vue'
var
	page = 1,
	timer = null,
	pages = 1;
	export default {
		components: {uniLoadMore},
		data() {
			return {
				listid:'',
				list:[],
				// list1:[],
				list1:[1,2,1,2,1,2,1,2,1,2,1,2,1],
				loadingText: '加载中...',
				loadingType: 0, //定义加载方式 0---contentdown  1---contentrefresh 2---contentnomore
				contentText: {
					contentdown: '上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '我也是有底线的~',
				},
			}
		},
		onPullDownRefresh: function() {
			this.liebiao()
		},
		onReachBottom: function() {
			// console.log(pages,page)
			if (page <= pages) {
				this.getmore();
				// console.log('数据+1')
			}else{
				// console.log('没有数据了')
				this.loadingType = 2
			}
		},
		onLoad(option){
			
			this.listid = option.id
			this.liebiao()
		},
		methods: {
			liebiao(){
					//章节列表
					uni.showLoading({
					    title: '加载中'
					});
					var _this = this
					var token = uni.getStorageSync('token')
					page = 1
					var data = {
						novel_id:_this.listid,//小说id
						page:page,
						limit:20
					}
					uni.request({
						url: getdata.websiteUrl + '/novel/section',
						header:{'content-type': "application/x-www-form-urlencoded",token:token},
						dataType: 'json',
						method: 'POST',
						data:data,
						success: res => {
							console.log(res)
							uni.hideLoading();
							uni.stopPullDownRefresh()
							if(res.data.code == 1){
								_this.list = []
								_this.list = res.data.data.list
								pages = res.data.data.count
								page++
								if(page > pages){
									this.loadingType = 2
								}
							}else{
								getdata.shou(res.data.msg)
							}
						},
						fail: res => {
							uni.hideLoading();
							uni.stopPullDownRefresh()
							getdata.shou('服务器断开链接')
						}
					});
			},
			getmore(){
					//章节列表
					var _this = this
					var token = uni.getStorageSync('token')
					var data = {
						novel_id:_this.listid,//小说id
						page:page,
						limit:20
					}
					_this.loadingType = 1 //正在加载
					uni.request({
						url: getdata.websiteUrl + '/novel/section',
						header:{'content-type': "application/x-www-form-urlencoded",token:token},
						dataType: 'json',
						method: 'POST',
						data:data,
						success: res => {
							if(res.data.code == 1){
								_this.list =_this.list.concat(res.data.data.list)
								page++
							}else{
								getdata.shou(res.data.msg)
							}
						},
						fail: res => {
							getdata.shou('服务器断开链接')
						}
					});
			},
			xsdetail(id,novel_id){
				uni.navigateTo({
					url:'../xsdetail/xsdetail?id=' + novel_id + '&novel_id=' + id
				})
			}
		}
	}
</script>

<style lang="scss">
.content{
	width: 100%;
	box-sizing: border-box;
	padding: 50rpx 30rpx;
	background-color: #FFFFFF;
	.xslist{
		border-bottom: 2rpx solid #E3DFDF;
		width: 100%;
		box-sizing: border-box;
		padding:35rpx 0;
		.xs_title{
			font-size: 26rpx;
			line-height: 1;
			font-family: PingFang SC;
			font-weight: bold;
			color: #302E37;
			margin-left: 30rpx;
		}
		.xs_name{
			font-size: 24rpx;
			line-height: 1;
			font-family: PingFang SC;
			color: #302E37;
			margin-top: 30rpx;
		}
	}
	.wu{
		text-align: center;
		font-size: 30rpx;
		color: #8D8D97;
	}
}
</style>
